using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace NppPluginNET
{
	/// <summary> Allow copy and cut for the current line, if no text is selected. </summary>
	partial class VisualStudioLineCopy
	{
		internal const string PluginName = "Visual Studio Line Copy";

		internal static void CommandMenuInit()
		{
			SetCommand(0, "CopyAllowLine", CopyAllowLine);
			SetCommand(1, "CutAllowLine", CutAllowLine);
		}

		internal static void PluginCleanUp()
		{
			// no clean up to do
		}

		/// <summary> Copy the selected text, or if no text is selected, copy the entire line. </summary>
		private static void CopyAllowLine()
		{
			Win32.SendMessage(GetCurrentScintilla(), SciMsg.SCI_COPYALLOWLINE, 0, 0);
		}

		/// <summary> Cut the selected text, or if no text is selected, cut the entire line. </summary>
		private static void CutAllowLine()
		{
			IntPtr scintilla = GetCurrentScintilla();

			int selectionStart = (int)Win32.SendMessage(scintilla, SciMsg.SCI_GETSELECTIONSTART, 0, 0);
			int selectionEnd = (int)Win32.SendMessage(scintilla, SciMsg.SCI_GETSELECTIONEND, 0, 0);

			if (selectionStart == selectionEnd) // no selection, cut the line
			{
				Win32.SendMessage(scintilla, SciMsg.SCI_LINECUT, 0, 0);
			}
			else
			{
				Win32.SendMessage(scintilla, SciMsg.SCI_CUT, 0, 0);
			}
		}
	}
}